package com.mou.controller.user;

import com.mou.dto.ProductFavoritesDTO;
import com.mou.entity.ProductFavorites;
import com.mou.result.Result;
import com.mou.service.ProductFavoritesService;
import com.mou.vo.ProductFavoritesVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/user/productFavorites")
@Slf4j
public class ProductFavoritesController {
    @Autowired
    private ProductFavoritesService productFavoritesService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody ProductFavoritesDTO productFavoritesDTO) {
        log.info("添加收藏:{}", productFavoritesDTO);
        productFavoritesService.add(productFavoritesDTO);
        return Result.success();
    }

    @PutMapping("/delete")
    public Result<String> delete(@RequestBody ProductFavoritesDTO ProductFavoritesDTO) {
        productFavoritesService.delete(ProductFavoritesDTO);
        return Result.success();
    }

    @PostMapping("/list")
    public Result<List<ProductFavoritesVO>> getProductFavorites(@RequestBody ProductFavoritesDTO productFavoritesDTO) {
        log.info("查询收藏:{}", productFavoritesDTO);
        List<ProductFavoritesVO> productFavoritesVO = productFavoritesService.getProductFavorites(productFavoritesDTO);
        return Result.success(productFavoritesVO);
    }
}
